using System;
using System.Collections.Generic;
using Lockstep.Math;
using Sirenix.OdinInspector;
using UnityEngine;

namespace Lockstep.Game {

    public enum SkillPartType { 
        None,
        Bullet,
        Audio,
    }

    [Serializable]
    public class SkillPart {
        public SkillPartType type;
        public LFloat startFrame;
        public LFloat lifeTime;

        [ShowIf("type", SkillPartType.Bullet)]
        public BulletConfig bulletConfig;
        public static LFloat AnimFrameScale = new LFloat(true, 1667);
        [HideInInspector] public LFloat DeadTimer => startTimer + lifeTime;
        [HideInInspector] public LFloat startTimer => startFrame * SkillPart.AnimFrameScale;

    }

    [Serializable]
    public class SkillInfo {
        public int id;
        public string animName;
        public LFloat CD;
        public LFloat doneDelay;
        public EColliderLayer targetLayer;
        public LFloat maxPartTime;
        public List<SkillPart> parts = new List<SkillPart>();

        public void DoInit(){
            parts.Sort((a, b) => LMath.Sign(a.startFrame - b.startFrame));
            var time = LFloat.MinValue;
            foreach (var part in parts) {
                var partDeadTime = part.DeadTimer;
                if (partDeadTime > time) {
                    time = partDeadTime;
                }
            }

            maxPartTime = time + doneDelay;
        }
    }
}